#-*- coding:utf-8 -*-
import os,re,chardet
import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
    reload(sys)
    sys.setdefaultencoding(default_encoding)

css_file_path = "/var/www/html/css_file/"
css_full_file = css_file_path + os.listdir(css_file_path)[0]


def TakeFileContent(filename):
    File = open(filename)
    FileContent = File.read()
    File.close()
    return FileContent

if os.path.isfile(css_full_file):
    FileContent = TakeFileContent(css_full_file)
else:
    print "2"

FileCharset = chardet.detect(FileContent)['encoding']


#FileContent = FileContent.decode(FileCharset)


NewFileContent = re.sub('{((\s*([^:]+)\s*:\s*([^;]+?)\s*;\s*)*?)}','|',FileContent).replace('\n','')#匹配规则
NewFileContent = re.sub('\/\*([\S\s]*?)\*\/','',NewFileContent)#删除注释
NewFileContent = re.sub('@(.*);','',NewFileContent).replace('/*','').replace('*/','')#删除@的字体和未被正则表达式匹配到的注释
NewFileContent = NewFileContent.split('|')
